﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UWP.Douban.Models;
using Windows.UI.Xaml.Navigation;

namespace UWP.Douban.Mvvm
{
    public class DouImDetailVm:BaseVm
    {
        private DoumailThread _doumailThread;

        public DouImDetailVm()
        {

        }
 
        public DoumailThread DoumailThread
        {
            get { return _doumailThread; }
            set
            {
                if (_doumailThread == value) return;
                _doumailThread = value;
                OnPropertyChanged();
            }
        }


        public override async void OnNavigatedTo(NavigationEventArgs e)
        {
            DoumailThread = await SampleData.SampleDataUtil.GetDouMailThread();

            foreach (var mail in DoumailThread.Doumails)
            {
                if (mail.SenderUser == null)
                {
                    mail.SenderUser = DoumailThread.MailUsers.Find(o => o.Id == mail.SenderId);
                }

                if (mail.ReceiverUser == null)
                {
                    mail.ReceiverUser = DoumailThread.MailUsers.Find(o => o.Id == mail.ReceiverId);
                }
            }

            base.OnNavigatedTo(e);
        }
    }
}
